﻿using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace DZPK
{
    public class TableInfo  // old version struct
    {
        public int tableIndex;
        public string tableName;
        public Int64 maxSeatCount;
        public Int64 minBuyChips;
        public Int64 maxBuyChips;
        public string serverIP;
        public string serverPort;

        public Dictionary<int, int> tableNumberMap;

        public TableInfo()
        {
            tableNumberMap = new Dictionary<int, int>();
        }
    }

    public class ServerInfo  // old version struct
    {
        public string serverIP;
        public string serverPort;
    }

    public class TableManager
    {
        public ConcurrentDictionary<int, Table> indexToTableMap;  // table id to table  
        public RoomConfigManager roomConfigManager;
        public string roomConfigFilename;

        //public Dictionary<string, TableInfo> tableMap;    // table type to table id
        //public Dictionary<int, ServerInfo> serverMap;     // table id to table ip port

        public TableManager()
        {
            indexToTableMap = new ConcurrentDictionary<int, Table>();
            roomConfigManager = RoomConfigManager.GetRoomConfigInstance();

            roomConfigFilename = "table_config.xml";
        }

        public void GetRoomInfomationFromConfigFile()
        {
            //roomConfigManager.ParseTableConfig(roomConfigFilename, out tableMap, out serverMap);
            roomConfigManager.ParseTableConfig_V2(roomConfigFilename, out indexToTableMap);
        }

        public void SendTableConfigFileRequest()
        {
            roomConfigManager.GetTableConfigFile(roomConfigFilename);
        }

        public void InitializeRooms()
        {
            GetRoomInfomationFromConfigFile();
        }

        public ServerInfo GetTableIpPortFromTableIndex(int index)
        {
            ServerInfo oInfo = null;

            //if (serverMap != null)
            //{
            //    serverMap.TryGetValue(index, out oInfo); 
            //}

            return oInfo;
        }
    }
}
